package com.xidian.yunwudemo.controller;

import com.xidian.yunwudemo.common.Result;
import com.xidian.yunwudemo.dto.*;
import com.xidian.yunwudemo.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/dataView")
public class DataViewController {
    @Autowired
    DataViewUserService dataViewUserService;

    @Autowired
    DataViewAdaptiveService dataViewAdaptiveService;

    @Autowired
    DataViewOverviewService dataViewOverviewService;

    @Autowired
    DataViewInfoService dataViewInfoService;

    @Autowired
    DataViewBiologyService dataViewBiologyService;
    /**
     * 获取用户认证方式24小时内的认证次数和认证耗时
     * @return authCount(认证次数),authTime(认证耗时)
     * TODO: websocket
     */
    @GetMapping("/userDay")
    public Result getUserDayData() {
        DataViewUserDto dvu = dataViewUserService.getUserDayData();
        return Result.OK(dvu);
    }

    /**
     * 获取用户认证方式一周内的认证次数和认证耗时
     * @return authCount(认证次数),authTime(认证耗时)
     */
    @GetMapping("/userWeek")
    public Result getUserWeekData() {
        DataViewUserDto dvu = dataViewUserService.getUserWeekData();
        return Result.OK(dvu);
    }

    /**
     * 获取用户认证方式总的认证次数和认证耗时
     * @return authCount(认证次数),authTime(认证耗时)
     * TODO: websocket
     */
    @GetMapping("/userAll")
    public Result getUserAllData() {
        DataViewUserDto dvu = dataViewUserService.getUserAllData();
        return Result.OK(dvu);
    }

    /* ========== 全局信息 ========= */

    /**
     * 获取该系统所有的认证次数与指标内容
     * @return countAll(总认证次数),metricsValue(指标内容)
     * TODO: websocket
     */
    @GetMapping("/allAuthCount")
    public Result getAllAuthCount() {
        DataViewOverViewDto ov = dataViewOverviewService.getOverviewData();
        return Result.OK(ov);
    }

    /**
     * 获取该系统三种认证服务的总认证次数
     * @return diffCount(不同认证方式的认证次数)
     * type Array(Object)
     * TODO: websocket
     * 可以省略
     * @GetMapping("/diffAuthCount")
     *     public Result getDiffAuthCount() {
     *         return null;
     *     }
     */

    /* ========= 生物认证 ======== */
    /**
     * 获取24小时内生物认证的置信度和软生物特征占比(只获取一周的数据)
     * @return [timeArray, confidenceOfFace, confidenceOfFingerPrint]
     * TODO: websocket
     */
    @GetMapping("/biologyDay")
    public Result getBiologyDay() {
        DataViewBiologyDto dvb = dataViewBiologyService.getBiologyDay();
        return Result.OK(dvb);
    }

    /**
     * 获取一周内生物认证的置信度和软生物特征占比
     * @return [timeArray, confidenceOfFace, confidenceOfFingerPrint]
     */
    @GetMapping("/biologyWeek")
    public Result getBiologyWeek() {
        DataViewBiologyDto dvb = dataViewBiologyService.getBiologyWeek();
        return Result.OK(dvb);
    }

    /**
     * 获取所有生物认证的置信度和软生物特征占比
     * @return [timeArray, confidenceOfFace, confidenceOfFingerPrint]
     * TODO: websocket
     */
    @GetMapping("/biologyAll")
    public Result getBiologyAll() {
        DataViewBiologyDto dvb = dataViewBiologyService.getBiologyAll();
        return Result.OK(dvb);
    }

    /* ========= 自适应认证 ======== */
    /**
     * 获取24小时内自适应认证各个认证方式的次数
     * @return [
     *      countNum: 各个方式认证次数——用于柱状图
     *      pieNum: 各个方式认证次数——用于饼图
     *      ]
     * TODO: websocket
     */
    @GetMapping("/adaptiveDay")
    public Result getAdaptiveDay() {
        DataViewAdaptiveDto res = dataViewAdaptiveService.getAdaptiveDayData();
        return Result.OK(res);
    }

    /**
     * 获取一周内自适应认证各个认证方式的次数
     * @return [
     *      countNum: 各个方式认证次数——用于柱状图
     *      pieNum: 各个方式认证次数——用于饼图
     *      ]
     */
    @GetMapping("/adaptiveWeek")
    public Result getAdaptiveWeek() {
        DataViewAdaptiveDto res = dataViewAdaptiveService.getAdaptiveWeekData();
        return Result.OK(res);
    }

    /**
     * 获取所有时间自适应认证各个认证方式的次数
     * @return [
     *      countNum: 各个方式认证次数——用于柱状图
     *      pieNum: 各个方式认证次数——用于饼图
     *   ]
     * TODO: websocket
     */
    @GetMapping("/adaptiveAll")
    public Result getAdaptiveAll() {
        DataViewAdaptiveDto res = dataViewAdaptiveService.getAdaptiveAllData();
        return Result.OK(res);
    }

    /**
     * 获取最近一段时间内的认证简短信息
     * @return [data]
     * TODO: websocket
     */
    @GetMapping("/info")
    public Result getDataViewInfo() {
        String[][] res = dataViewInfoService.getLastAuthRecord();
        return Result.OK(res);
    }
}
